import axios from "axios";
// 进度条
import "ant-design-vue/dist/antd.css";
import commmon from "../utils/common.js";
export default {
  install: function (vue) {
    var result = axios.create({
      // baseURL: "http://flood-control-emulate.rexhub.space",
      baseURL: "",
    });

    result.interceptors.request.use(
      function (request) {
        console.log("token", window.localStorage.getItem("token"));
        if (window.localStorage.getItem("token") != null) {
          console.log("token");
          request.headers.Authorization = window.localStorage.getItem("token");
        }
        return request;
      },
      (error) => {
        console.log("request", error);
      }
    );
    result.interceptors.response.use(
      (response) => {
        console.log("currentData", response);
        // 如果没有爆出401 能够成功查看 但是被后端拦截了 就删掉token
        if (response.data.msg == "没有权限") {
          localStorage.removeItem("token");
          commmon.notify("warning", "权限失效,请重新登录");
        }
        return response;
      },
      (error) => {
        console.log("response", error);
          if (error.response) {
          console.log("response", error);
          if(error.response.status!=401)
          commmon.notify("warning", "请求失败");
        }
      }
    );
    vue.prototype.$http = result;
  },
};
